package com.lab.widget.pager;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.support.v4.graphics.drawable.DrawableCompat;
import android.support.v4.graphics.drawable.DrawableWrapper;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.cuitrip.business.tripservice.ui.IconTextView;
import com.cuitrip.service.R;
import com.cuitrip.util.ResourceUtil;

import butterknife.Bind;
import butterknife.ButterKnife;
import de.hdodenhof.circleimageview.CircleImageView;

/**
 * 自定义tab布局
 * Created by ak
 */
public class ImageTabView extends LinearLayout implements TabPageIndicator.ITabView {

    private Context mContext;

    private int mIndex;

    @Bind(R.id.tabIcon)
    ImageView mTabLogo;

    @Bind(R.id.tab_tv)
    TextView mTabText;

    @Bind(R.id.tab_has_notice)
    CircleImageView tabHasNotice;

    private int mMaxTabWidth;

    public ImageTabView(Context context) {
        this(context, null);
    }

    public ImageTabView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public ImageTabView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initInternal(attrs, context, defStyleAttr);
    }

    private void initInternal(AttributeSet attrs, Context context, int defStyle) {
        mContext = context;
        LayoutInflater.from(mContext).inflate(R.layout.image_text_tab_view, this);
        ButterKnife.bind(this);
    }


    public void setUnRead(boolean unRead){
        tabHasNotice.setVisibility(unRead ? VISIBLE : INVISIBLE);
    }


    public void setTabImageResource(int res){
        mTabLogo.setImageResource(res);
    }

    public void setTabText(CharSequence text){
        mTabText.setText(text);
    }


    public int getIndex() {
        return mIndex;
    }

    public void setIndex(int index) {
        this.mIndex = index;
    }

    public void setmMaxTabWidth(int maxTabWidth){
        mMaxTabWidth = maxTabWidth;
    }

    @Override
    public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);

        // Re-measure if we went beyond our maximum size.
        if (mMaxTabWidth > 0 && getMeasuredWidth() > mMaxTabWidth) {
            super.onMeasure(MeasureSpec.makeMeasureSpec(mMaxTabWidth, MeasureSpec.EXACTLY),
                    heightMeasureSpec);
        }
    }

}
